﻿<cfsilent>
	<cfscript>
		
		sql = "SELECT a.institute_name 
				FROM t_institute a 
				ORDER BY a.institute_id DESC";
		queryObj = new Query( datasource=application.dnsSlave ); 
		rs_ins= queryObj.execute( sql=sql ).getResult();
		
		temFile = GetTempDirectory() & createUUID() & ".xls";
		downFile = URLEncodedFormat("课程信息录入模板", "utf-8");
		
		excel = getProperty("serviceFactory").getBean("spreadSheetObject");
		
		/* 创建工作簿 */
		spreadsheetObj = excel.SpreadSheetNew("课程", false);
		
		/* 添加表头 */
		excel.SpreadsheetAddrow(spreadsheetObj, "任课单位,课程号,课程名称,课程英文名称,学分,排课周学时,总学时,理论学时,实践学时,上机学时,课程简介,参考书目,课程类别");
		
		/* 添加部门信息参考 */
		excel.SpreadsheetCreateSheet (spreadsheetObj, "任课单位参考信息");
		excel.SpreadsheetSetActiveSheet (spreadsheetObj, "任课单位参考信息");
		
		excel.SpreadsheetAddrow(spreadsheetObj, "单位全称");
		
		for (  a=1; a LTE rs_ins.recordCount; a++ ) {
			
			/* 构建部门参考信息 */
			rowData = rs_ins['institute_name'][a];
			
			/* 写入部门信息 */
			excel.SpreadsheetAddrow(spreadsheetObj, rowData);
		}
		
		excel.SpreadsheetSetActiveSheet (spreadsheetObj, "课程");
		excel.SpreadSheetWrite(spreadsheetObj, temFile, true);

	</cfscript>

	<cfheader name="Content-Disposition" value="attachment; filename=#downFile#.xls" />
	<cfcontent file="#temFile#" reset="yes" type="application/msexcel" deletefile="yes" />	

</cfsilent>